package com.hery.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



public class ConfigFactory {
	private String filePath = "/conf.properties";
	private Logger log = LoggerFactory.getLogger(ConfigFactory.class);
	Properties prop = null;
	
	private static ConfigFactory config;
	
	private ConfigFactory(){
		init();
	}
	
	public static ConfigFactory getInstance(){
		if(config == null){
			config = new ConfigFactory();
		}
		return config;
	}
	
	public void init(){
		if(prop == null){
			prop = new Properties();
		}
		InputStream input = this.getClass().getResourceAsStream(filePath);
	
		try {
			prop.load(input);
		} catch (IOException e) {
			log.error("conf load error:", e);
		}
	}
	
	
	public String getProperties(String key){
		log.info(key  + ":" + prop.getProperty (key));
		return prop.getProperty (key);
	}
	public String getProperties(String key,String defaultValue){
		String value=getProperties(key);
		if(value==null){
			value=defaultValue;
		}
		return value;
	}
}
